﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Libs.Db;

namespace Libs.HR
{
    public class ResignLog
    {
        public int LogID { get; set; }
        public int EmployeeID { get; set; }
        public DateTime ResignTime { get; set; }
        public DateTime ApplyTime { get; set; }
        public DateTime LogTime { get; set; }
        public string Description { get; set; }
        public int ReturnValue { get; set; }

        public ResignLog()
        {

        }

        ~ResignLog()
        {

        }

        public virtual void Dispose()
        {

        }

        /// <summary>
        /// Lấy giá trị ResignLog theo ID
        /// </summary>
        /// <param name="LogID"></param>
        /// <returns></returns>
        public ResignLog Get(int logID)
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetInstanceSP<ResignLog>("sp_ResignLog_Select",
                new SqlParameter("@LogID", logID));
        }

        /// <summary>
        /// Lấy giá trị ResignLog theo ID
        /// </summary>
        /// <returns></returns>
        public ResignLog Get()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetInstanceSP<ResignLog>("sp_ResignLog_Select",
                new SqlParameter("@LogID", LogID));
        }

        /// <summary>
        /// Thêm mới ResignLog
        /// </summary>
        public void Add()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            SqlParameter[] pars = new SqlParameter[5];
            pars[0] = new SqlParameter("@ReturnValue", SqlDbType.Int) { Direction = ParameterDirection.Output };
            pars[1] = new SqlParameter("@EmployeeID", EmployeeID);
            pars[2] = new SqlParameter("@ResignTime", ResignTime);
            pars[3] = new SqlParameter("@ApplyTime", ApplyTime);
            pars[4] = new SqlParameter("@Description", Description);

            db.ExecuteNonQuerySP("sp_ResignLog_Insert", pars);
            LogID = Convert.ToInt32(pars[0].Value);
        }

        /// <summary>
        /// Cập nhật ResignLog
        /// </summary>
        public void Update()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            SqlParameter[] pars = new SqlParameter[6];
            pars[0] = new SqlParameter("@ReturnValue", SqlDbType.Int) { Direction = ParameterDirection.Output };
            pars[1] = new SqlParameter("@LogID", LogID);
            pars[2] = new SqlParameter("@EmployeeID", EmployeeID);
            pars[3] = new SqlParameter("@ResignTime", ResignTime);
            pars[4] = new SqlParameter("@ApplyTime", ApplyTime);
            pars[5] = new SqlParameter("@Description", Description);

            db.ExecuteNonQuerySP("sp_ResignLog_Update", pars);
            ReturnValue = Convert.ToInt32(pars[0].Value);
        }

        /// <summary>
        /// Xoá ResignLog
        /// </summary>
        /// <param name="logID"></param>
        public void Delete(int logID)
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);

            db.ExecuteNonQuerySP("sp_ResignLog_Delete",
                new SqlParameter("@LogID", logID));
        }

        /// <summary>
        /// Xoá ResignLog
        /// </summary>
        public void Delete()
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);

            db.ExecuteNonQuerySP("sp_ResignLog_Delete",
                new SqlParameter("@LogID", LogID));
        }

        public DataTable GetListT(DateTime beginTime, DateTime endTime)
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetDataTableSP("sp_ResignLog_SelectList",
                new SqlParameter("@BeginTime", beginTime),
                new SqlParameter("@EndTime", endTime));
        }

        public List<ResignLog> GetList(DateTime beginTime, DateTime endTime)
        {
            DbHelper db = new DbHelper(Config.HRConnectionStrings);
            return db.GetListSP<ResignLog>("sp_ResignLog_SelectList",
                new SqlParameter("@BeginTime", beginTime),
                new SqlParameter("@EndTime", endTime));
        }
    }
}
